package com.sy.simpleegg.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.sy.simpleegg.R
import com.sy.simpleegg.base.BaseMvpFragment
import com.sy.simpleegg.config.Config
import com.sy.simpleegg.constant.Constant
import com.sy.simpleegg.constant.Constant.CHANNEL_COUNT_DEFAULT
import com.sy.simpleegg.constant.Constant.STOCK_MAX_DEFAULT
import com.sy.simpleegg.databinding.FragmentOperatingStatisticsBinding
import com.sy.simpleegg.ext.logFile
import com.sy.simpleegg.mvp.contract.OperatingStatisticsContract
import com.sy.simpleegg.mvp.presenter.OperatingStatisticsPresenter
import com.sy.simpleegg.util.Preference

class OperatingStatisticsFragment :
    BaseMvpFragment<OperatingStatisticsContract.View, OperatingStatisticsContract.Presenter, FragmentOperatingStatisticsBinding>(),
    OperatingStatisticsContract.View {

    companion object {
        fun getInstance(): OperatingStatisticsFragment = OperatingStatisticsFragment()
    }

    /**
     * 设备编号
     */
    private var devNumber: String by Preference(Constant.SETTING_DEVICE_NUMBER, "")

    /**
     * 货道数量
     */
    private var channelCount: Int by Preference(
        Constant.SETTING_CHANNEL_COUNT,
        CHANNEL_COUNT_DEFAULT
    )

    /**
     * 库存最大值
     */
    private var stockMax: Int by Preference(Constant.SETTING_STOCK_MAX, STOCK_MAX_DEFAULT)

    override fun createPresenter(): OperatingStatisticsContract.Presenter = OperatingStatisticsPresenter(lifecycleScope)

    override fun attachLayoutRes(): Int = R.layout.fragment_operating_statistics

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        openEventBus = false
        isCountDownBackHome = false
    }

    override fun initView(view: View) {
        super.initView(view)

        binding.tvOnDutyTotalInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvOnDutyBillInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvOnDutyCoinInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvOnDutyMobileInAmountChar.text = Config.CURRENCY_SYMBOLS

        binding.tvDeviceDayTotalInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceDayBillInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceDayCoinInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceDayMobileInAmountChar.text = Config.CURRENCY_SYMBOLS

        binding.tvDeviceTotalInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceBillInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceCoinInAmountChar.text = Config.CURRENCY_SYMBOLS
        binding.tvDeviceMobileInAmountChar.text = Config.CURRENCY_SYMBOLS

//        binding.rlTouch.setTouchListener(object : TouchRelativeLayout.TouchListener {
//            override fun touch() {
//                startCountDown()
//            }
//        })
    }

    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
    ): FragmentOperatingStatisticsBinding {
        return FragmentOperatingStatisticsBinding.inflate(inflater, container, false)
    }

    override fun lazyLoad() {

    }

    override fun onResume() {
        super.onResume()
        logFile("${javaClass.simpleName} onResume")
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (hidden) {
            logFile("${javaClass.simpleName}隐藏")
        } else {
            logFile("${javaClass.simpleName}显示")
        }
    }


    override fun showLoading() {

    }

    override fun hideLoading() {

    }
}